package com.kotiln.lgc.guidepagedemo.videoguide;

import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager.widget.ViewPager;

import com.kotiln.lgc.guidepagedemo.R;
import com.kotiln.lgc.guidepagedemo.viewpager.ViewPagerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author $
 * @fileName VideoActivitiy
 * @date2021/3/22 15:13
 * @describe TODO
 * @desc videoview实现引导页
 */
public class VideoActivity extends FragmentActivity {
    private Button btn;
    private ViewPagerAdapter mViewPagerAdapter;
    private List<Fragment> fragments=new ArrayList<Fragment>();
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video);
//        requestWindowFeature(Window.FEATURE_NO_TITLE);
//        //设置窗口全屏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        ViewPager viewpager = findViewById(R.id.viewpager);
        btn=findViewById(R.id.btn);
        //预加载
        viewpager.setOffscreenPageLimit(3);
        for(int i=0;i<3;i++){
            VideoGuideFragment fragment=new VideoGuideFragment();
            Bundle bundle=new Bundle();
            bundle.putInt("index",i);
            fragment.setArguments(bundle);
            fragments.add(fragment);
        }
        mViewPagerAdapter=new ViewPagerAdapter(getSupportFragmentManager(),fragments);
        viewpager.setAdapter(mViewPagerAdapter);

        viewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                btn.setVisibility(position==2?View.VISIBLE:View.INVISIBLE);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }
}
